package org.server.action.actionController.login;

import com.alibaba.fastjson.JSON;
import com.iohao.game.action.skeleton.annotation.ActionController;
import com.iohao.game.action.skeleton.annotation.ActionMethod;
import com.iohao.game.action.skeleton.core.flow.FlowContext;
import com.iohao.game.bolt.broker.client.kit.UserIdSettingKit;
import lombok.extern.slf4j.Slf4j;
import org.server.action.ActionCmd;
import org.server.domain.Login.LoginVerify;
import org.server.domain.Login.MyAttachment;
import org.server.domain.Result.Msg;
import org.server.domain.Login.UserInfomation;
import org.server.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Admin
 */
@Slf4j
@Component
@ActionController(ActionCmd.LOG)
public class LoginAction {
    private LoginService loginService;

    /**
     * 玩家登陆
     *
     * @param loginVerify
     * @param flowContext
     * @return org.server.domain.Result.Msg<java.lang.String>
     * @author Tang
     * @date 2023/3/1 13:13
     **/
    @ActionMethod(ActionCmd.LOG_LOGIN)
    public Msg login(LoginVerify loginVerify, FlowContext flowContext) {
        if (loginVerify == null || loginVerify.password == null || loginVerify.account == null) {
            return null;
        }
        MyAttachment check = loginService.check(flowContext, loginVerify);
        if(check == null) {
            return new Msg("false");
        }
        Msg msg = new Msg();
        msg.data = JSON.toJSONString(check);
        return msg;
    }

    /**
     * 心跳检测
     *
     * @param
     * @return void
     * @author Tang
     * @date 2023/3/1 13:13
     **/
    @ActionMethod(ActionCmd.LOG_IDLE)
    public void idle() {
    }

    @Autowired
    public void setLoginService(LoginService loginService) {
        this.loginService = loginService;
    }
}
